home *** CD-ROM | disk | FTP | other *** search
/ PC World 2007 December / PCWorld_2007-12_cd.bin / domacnost a kancelar / autoit / autoit-v3-setup.exe / Examples / Helpfile / _SQLite_LastInsertRowID.au3 < prev    next >
Text File  |  2007-09-08  |  2KB  |  57 lines

  1. #include <SQLite.au3>
  2. #include <SQLite.dll.au3>
  3. #include <Array.au3>
  4.  
  5. Local $aResult, $iRows, $iColumns, $iRval
  6.  
  7. _SQLite_Startup ()
  8. If @error > 0 Then
  9.     MsgBox(16, "SQLite Error", "SQLite.dll Can't be Loaded!")
  10.     Exit - 1
  11. EndIf
  12. _SQLite_Open () ; Open a :memory: database
  13. If @error > 0 Then
  14.     MsgBox(16, "SQLite Error", "Can't Load Database!")
  15.     Exit - 1
  16. EndIf
  17.  
  18. ;Example Table
  19. ;     Name        | Age
  20. ;     -----------------------
  21. ;     Alice       | 43
  22. ;     Bob         | 28
  23. ;     Cindy       | 21
  24.  
  25. ; _SQLite_Exec() and _SQLite_Execute() are quite similar
  26. If Not _SQLite_Exec (-1, "CREATE TEMP TABLE persons (Name, Age);") = $SQLITE_OK Then _
  27.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  28. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Alice','43');") = $SQLITE_OK Then _
  29.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  30. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Bob','28');") = $SQLITE_OK Then _
  31.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  32. If Not _SQLite_Exec (-1, "INSERT INTO persons VALUES ('Cindy','21');") = $SQLITE_OK Then _
  33.         MsgBox(16, "SQLite Error", _SQLite_ErrMsg ())
  34.  
  35. ; _SQLite_LastInsertRowID() tells us Cindy's row
  36. MsgBox( 0, "_SQLite_LastInsertRowID()", _SQLite_LastInsertRowID() )
  37.  
  38. ; Query
  39. $iRval = _SQLite_GetTable (-1, "SELECT * FROM persons;", $aResult, $iRows, $iColumns)
  40. If $iRval = $SQLITE_OK Then
  41. ;~     $aResult Looks Like this:
  42. ;~         [0]    = 8
  43. ;~         [1]    = Name
  44. ;~         [2]    = Age
  45. ;~         [3]    = Alice
  46. ;~         [4]    = 43
  47. ;~         [5]    = Bob
  48. ;~         [6]    = 28
  49. ;~         [7]    = Cindy
  50. ;~         [8]    = 21
  51.     _ArrayDisplay($aResult, "Query Result")
  52. Else
  53.     MsgBox(16, "SQLite Error: " & $iRval, _SQLite_ErrMsg ())
  54. EndIf
  55.  
  56. _SQLite_Close ()
  57. _SQLite_Shutdown ()